package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.vo.BaseRespVo;
import com.cskaoyan.bean.vo.WxUserIndexVo;
import com.cskaoyan.service.OrderService;
import com.cskaoyan.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *  小程序用户Controller
 *
 */
@RestController
@RequestMapping("wx/user")
public class WxUserController {
    @Autowired
    OrderService orderService;

    @Autowired
    UserService userService;

    // 用户主页
    @RequestMapping("index")
    public BaseRespVo userIndex(){
        Subject subject = SecurityUtils.getSubject();
        String username = (String) subject.getSession().getAttribute("username");
        int userId = userService.getUserId(username);
        WxUserIndexVo wxUserIndexVo = orderService.getUserIndex(userId);
        return BaseRespVo.ok(wxUserIndexVo);
    }

}
